using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Castle.MonoRail.ActiveRecordSupport;
using Castle.MonoRail.Framework;
using ElevatorSpeeches.Framework;
using System.Collections.Generic;

namespace ElevatorSpeeches.Controllers
{

    [Layout("default"), Rescue("generalerror")]
    public class UserController : BaseController
    {
        public const string USER_SAVED_STRING = "Registration Complete!";

        public void Registration()
        {
            PropertyBag["Errors"] = new List<string>();
        }

        public void Registration([ARDataBind("User", Validate = true)] User user)
        {
            if (user.IsValid())
            {
                user.Save();
				GoHomeWithMessage(USER_SAVED_STRING);
            }
            else
            {
                PropertyBag["user"] = user;
                PropertyBag["Errors"] = user.ValidationErrorMessages;
            }
        }


		public void Login()
		{
		}


		public void Login(string userName, string password)
		{
			User user = User.Login(userName, password);

			if (null == user)
			{
				PropertyBag["Errors"] = "Invalid login";
			}
			else
			{
				GoHomeWithMessage("Logged in!");				
			}						
		}




        public void Save()
        {
            
        }
    }
}
